﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DepBank;
using System.IO;
namespace TestBench
{
    public partial class AlgoEval : Form
    {
        public AlgoEval()
        {
            InitializeComponent();
        }
        private Dictionary<string, string> GetGRDic()
        {
            Dictionary<string, string> parameterCount = new Dictionary<string, string>();
            parameterCount.Add("arg", "S H D");
            parameterCount.Add("arg_mod", "S H D");
            parameterCount.Add("aux", "H D");
            parameterCount.Add("ccomp", "S H D");
            parameterCount.Add("cmod", "S H D");
            parameterCount.Add("comp", "H D");
            parameterCount.Add("conj", "H D");
            parameterCount.Add("csubj", "H D I");
            parameterCount.Add("det", "H D");
            parameterCount.Add("dobj", "H D");
            parameterCount.Add("iobj", "H D");
            parameterCount.Add("ncmod", "S H D");
            parameterCount.Add("ncsubj", "H D I");
            parameterCount.Add("obj", "H D");
            parameterCount.Add("obj2", "H D");
            parameterCount.Add("passive", "H");
            parameterCount.Add("pcomp", "H D");
            parameterCount.Add("pmod", "H D");
            parameterCount.Add("ta", "S H D");
            parameterCount.Add("xcomp", "S H D");
            parameterCount.Add("xmod", "S H D");
            parameterCount.Add("xsubj", "H D I");
            return parameterCount;
        }


        private void btnEval_Click(object sender, EventArgs ex)
        {
            char evaluationSet = 'd';
            string outputFile = @"C:\Data\sriout\result";
            using (DepBank_DBDataContext context = new DepBank_DBDataContext())
            {
                using (StreamWriter sw = new StreamWriter(outputFile))
                {
                    sw.WriteLine("SenID\tF-Value\tPrecision\tRecall");
                    float totalPrecision = 0;
                    float totalRecall = 0;
                    float totalFValue = 0;
                    IRASPEval algo = new FullEvalAlgo();

                    var mainGoldSet = from goldStd in context.TBL_GoldStandard_GRs where goldStd.EvaluationSetType == evaluationSet select goldStd;
                    var mainEvalSet = from eval in context.TBL_Evals where eval.EvaluationSetType == evaluationSet && eval.Rank == 1 select eval;

                    int?[] sentenceIDs = (from goldStd in mainGoldSet select goldStd.SentenceID).Distinct<int?>().OrderBy(senID => senID.Value).ToArray<int?>();
                    Dictionary<string, int> dicInBoth = new Dictionary<string, int>();
                    Dictionary<string, int> dicGoldOnly = new Dictionary<string, int>();
                    Dictionary<string, int> dicEvalOnly = new Dictionary<string, int>();

                    
                    foreach (int? nullableSenID in sentenceIDs)
                    {

                        int senID = nullableSenID.Value;
                        var currentGoldSet = from g in mainGoldSet where g.SentenceID.Value == senID select g;
                        var currentEvalSet = from e in mainEvalSet where e.SentenceID.Value == senID select e;
                        var inBoth = from g in currentGoldSet join e in currentEvalSet on new { g.GRType, g.SubType, g.H_Word, g.D_Word, g.InitGR } equals new { e.GRType, e.SubType, e.H_Word, e.D_Word, e.InitGR } select g;
                        var goldOnly = from g in currentGoldSet join e in currentEvalSet on new { g.GRType, g.SubType, g.H_Word, g.D_Word, g.InitGR } equals new { e.GRType, e.SubType, e.H_Word, e.D_Word, e.InitGR } into jset from s in jset.DefaultIfEmpty() where jset.Count() == 0 select g;
                        var evalOnly = from e in currentEvalSet join g in currentGoldSet on new { e.GRType, e.SubType, e.H_Word, e.D_Word, e.InitGR } equals new { g.GRType, g.SubType, g.H_Word, g.D_Word, g.InitGR } into jset from s in jset.DefaultIfEmpty() where jset.Count() == 0 select e;
                        TBL_GoldStandard_GR[] arrInBoth = inBoth.ToArray();
                        TBL_GoldStandard_GR[] arrGoldOnly = goldOnly.ToArray();
                        TBL_Eval[] arrEvalOnly = evalOnly.ToArray();

                        //var currentInBoth = from g in inBoth where g.SentenceID==senID select g;
                        //var currentGoldOnly = from g in goldOnly where g.SentenceID == senID select g;
                        //var currentEvalOnly = from g in evalOnly where g.SentenceID == senID select g;

                        //TBL_GoldStandard_GR[] arrInBoth = currentInBoth.ToArray();
                        //TBL_GoldStandard_GR[] arrGoldOnly = currentGoldOnly.ToArray();
                        //TBL_Eval[] arrEvalOnly = currentEvalOnly.ToArray();



                        int intInBothCount = arrInBoth.Length;
                        int intGoldOnlyCount = arrGoldOnly.Length;
                        int intEvalOnlyCount = arrEvalOnly.Length;

                        float precision = (float)(intInBothCount) / (float)(intInBothCount + intEvalOnlyCount);
                        float recall = (float)intInBothCount / (float)(intInBothCount + intGoldOnlyCount);
                        float fvalue = (2 * precision * recall) * 100 / (precision + recall);

                        totalPrecision += precision;
                        totalRecall += recall;
                        totalFValue += fvalue;

                        string value = senID + "\t" + fvalue + "\t" + precision + "\t" + recall;
                        sw.WriteLine(value);

                        var inBothGRCount = from ib in arrInBoth group ib by ib.GRType into ibg select new { GR = ibg.Key, Clount = ibg.Count() };
                        var inGoldOnlyGRCount = from ig in arrGoldOnly group ig by ig.GRType into igg select new { GR = igg.Key, Count = igg.Count() };
                        var inEvalOnlyGRCount = from ie in arrEvalOnly group ie by ie.GRType into ieg select new { GR = ieg.Key, Count = ieg.Count() };

                        foreach (var x in inBothGRCount) {
                            if (dicInBoth.Keys.Contains(x.GR))
                            {
                                dicInBoth[x.GR]++;
                            }
                            else {
                                dicInBoth.Add(x.GR, 1);
                            }
                        }


                        foreach (var x in inGoldOnlyGRCount)
                        {
                            if (dicGoldOnly.Keys.Contains(x.GR))
                            {
                                dicGoldOnly[x.GR]++;
                            }
                            else
                            {
                                dicGoldOnly.Add(x.GR, 1);
                            }
                        }


                        foreach (var x in inEvalOnlyGRCount)
                        {
                            if (dicEvalOnly.Keys.Contains(x.GR))
                            {
                                dicEvalOnly[x.GR]++;
                            }
                            else
                            {
                                dicEvalOnly.Add(x.GR, 1);
                            }
                        }

                    }

                    sw.WriteLine("-----------------------------------------------------------");
                    sw.WriteLine("In both");
                    var inBothSorted = from x in dicInBoth orderby x.Value select new { GR = x.Key, Count = x.Value };
                    foreach (var x in inBothSorted) {
                        sw.WriteLine(x.GR + "\t\t" + x.Count);
                    }
                    sw.WriteLine("-----------------------------------------------------------");
                    sw.WriteLine("In Gold Only");
                    var inGoldSorted = from x in dicGoldOnly orderby x.Value select new { GR = x.Key, Count = x.Value };
                    foreach (var x in inGoldSorted)
                    {
                        sw.WriteLine(x.GR + "\t\t" + x.Count);
                    }
                    sw.WriteLine("-----------------------------------------------------------");
                    sw.WriteLine("In Eval Only");
                    var inEvalSorted = from x in dicEvalOnly orderby x.Value select new { GR = x.Key, Count = x.Value };
                    foreach (var x in inEvalSorted)
                    {
                        sw.WriteLine(x.GR + "\t\t" + x.Count);
                    }
                    

                 }
            }


        }


        private void btnFindBestParse_Click(object sender, EventArgs ex)
        {
            char evaluationSet = 't';
            string outputFile = @"C:\Data\sriout\max_out";
            using (DepBank_DBDataContext context = new DepBank_DBDataContext())
            {
                using (StreamWriter sw = new StreamWriter(outputFile))
                {
                    sw.WriteLine("SenID\tF-Value\tPrecision\tRecall");
                    float totalPrecision = 0;
                    float totalRecall = 0;
                    float totalFValue = 0;
                    IRASPEval algo = new FullEvalAlgo();

                    var goldSet = from goldStd in context.TBL_GoldStandard_GRs where goldStd.EvaluationSetType == evaluationSet select goldStd;
                    var evalSet = from eval in context.TBL_Evals where eval.EvaluationSetType == evaluationSet select eval;

                    int?[] sentenceIDs = (from goldStd in goldSet select goldStd.SentenceID).Distinct<int?>().OrderBy(senID => senID.Value).ToArray<int?>();


                    foreach (int? nullableSenID in sentenceIDs)
                    {
                        float maxPrecision = 0;
                        float maxRecall = 0;
                        float maxFValue = 0;
                        int senID = nullableSenID.Value;

                        int maxPrecisoinParseID = 0;
                        int maxRecallParseID = 0;
                        int maxFValueParseID = 0;
                        for (int i = 1; i <= 10; i++)
                        {

                            var currentGoldSet = from g in goldSet where g.SentenceID.Value == senID select g;
                            var currentEvalSet = from e in evalSet where e.SentenceID.Value == senID && e.ParseID == i select e;

                            var inBoth = from g in currentGoldSet join e in currentEvalSet on new { g.GRType, g.SubType, g.H_Word, g.D_Word, g.InitGR } equals new { e.GRType, e.SubType, e.H_Word, e.D_Word, e.InitGR } select g;
                            var goldOnly = from g in currentGoldSet join e in currentEvalSet on new { g.GRType, g.SubType, g.H_Word, g.D_Word, g.InitGR } equals new { e.GRType, e.SubType, e.H_Word, e.D_Word, e.InitGR } into jset from s in jset.DefaultIfEmpty() where jset.Count() == 0 select g;
                            var evalOnly = from e in currentEvalSet join g in currentGoldSet on new { e.GRType, e.SubType, e.H_Word, e.D_Word, e.InitGR } equals new { g.GRType, g.SubType, g.H_Word, g.D_Word, g.InitGR } into jset from s in jset.DefaultIfEmpty() where jset.Count() == 0 select e;

                            TBL_GoldStandard_GR[] arrInBoth = inBoth.ToArray();
                            TBL_GoldStandard_GR[] arrGoldOnly = goldOnly.ToArray();
                            TBL_Eval[] arrEvalOnly = evalOnly.ToArray();

                            int intInBothCount = arrInBoth.Length;
                            int intGoldOnlyCount = arrGoldOnly.Length;
                            int intEvalOnlyCount = arrEvalOnly.Length;

                            float precision = (float)(intInBothCount) / (float)(intInBothCount + intEvalOnlyCount);
                            float recall = (float)intInBothCount / (float)(intInBothCount + intGoldOnlyCount);
                            float fvalue = (2 * precision * recall) * 100 / (precision + recall);

                            if (maxPrecision < precision)
                            {
                                maxPrecision = precision;
                                maxPrecisoinParseID = i;
                            }
                            if (maxRecall < recall)
                            {
                                maxRecall = recall;
                                maxRecallParseID = i;
                            }
                            if (maxFValue < fvalue)
                            {
                                maxFValue = fvalue;
                                maxFValueParseID = i;
                            }

                        }
                        string value = senID + "\t" + maxFValue+"\t"+maxFValueParseID + "\t" + maxPrecision +"\t"+maxPrecisoinParseID+ "\t" + maxRecall+"\t"+maxRecallParseID;
                        sw.WriteLine(value);

                    }

                }
            }
        }

        private void btnRASPOut_Click(object sender, EventArgs ea)
        {
            string raspOut = @"C:\Data\sriout\rasp_out";
            char evaluationSet = 't';
            string newLine = "\n";
            int numOfPasrses = 1;
            Dictionary<string, string> grTemplateDic = GetGRDic();

            using (DepBank_DBDataContext context = new DepBank_DBDataContext())
            {
                using (StreamWriter sw = new StreamWriter(raspOut))
                {
                    var toBeEvalSet = from e in context.TBL_Evals where e.EvaluationSetType == evaluationSet && e.ParseID <= numOfPasrses select e;
                    int?[] sentenceIDs = (from goldStd in context.TBL_GoldStandard_GRs where goldStd.EvaluationSetType == evaluationSet select goldStd.SentenceID).Distinct<int?>().OrderBy(senID => senID.Value).ToArray<int?>();
                    foreach (int? nullableSenID in sentenceIDs)
                    {
                        int senID = nullableSenID.Value;
                        string sentence = (from s in context.TBL_Sens where s.EvaluationSetType == evaluationSet && s.SentenceID == senID select s.RASP_Out).Single();
                        sw.Write(sentence + newLine);
                        StringBuilder grSet = new StringBuilder();
                        for (int i = 1; i <= numOfPasrses; i++)
                        {
                            string listName = "gr-list: " + i;
                            sw.Write(listName + newLine);
                            var currentParseToBeEval = from tbe in toBeEvalSet where tbe.SentenceID==senID && tbe.ParseID == i select tbe;
                            
                            foreach (var gr in currentParseToBeEval)
                            {
                                string grType = gr.GRType.Trim();
                                grSet.Append("(|");
                                grSet.Append(grType);
                                grSet.Append("|");
                                string template = grTemplateDic[grType];

                                if (template.Contains("S"))
                                {
                                    string subtype = gr.SubType;
                                    if (!String.IsNullOrEmpty(subtype) && subtype != "###sub")
                                    {
                                        grSet.Append(" |");
                                        grSet.Append(subtype.Trim());
                                        grSet.Append("|");
                                    }
                                    else
                                    {
                                        grSet.Append(" _");
                                    }
                                }

                                if (template.Contains("H"))
                                {
                                    if (gr.H_Location.HasValue)
                                    {
                                        grSet.Append(" |");
                                        grSet.Append(gr.H_Word.Trim());
                                        grSet.Append(":");
                                        grSet.Append(gr.H_Location.Value);
                                        grSet.Append("_");
                                        grSet.Append(gr.H_RPOS.Trim());
                                        grSet.Append("|");
                                    }
                                    else
                                    {
                                        if (grType == "conj")
                                        {
                                            grSet.Append(" |;|");
                                        }
                                        else
                                        {
                                            grSet.Append(" |ellip|");
                                        }
                                    }
                                }

                                if (template.Contains("D"))
                                {
                                    if (gr.D_Location.HasValue)
                                    {
                                        if (gr.D_Location.HasValue)
                                        {
                                            grSet.Append(" |");
                                            grSet.Append(gr.D_Word.Trim());
                                            grSet.Append(":");
                                            grSet.Append(gr.D_Location.Value);
                                            grSet.Append("_");
                                            grSet.Append(gr.D_RPOS.Trim());
                                            grSet.Append("|");
                                        }
                                        else
                                        {
                                            grSet.Append(" |ellip|");
                                        }
                                    }
                                }

                                if (template.Contains("I"))
                                {
                                    if (!String.IsNullOrEmpty(gr.InitGR) && gr.InitGR != "###init")
                                    {
                                        grSet.Append(" |");
                                        grSet.Append(gr.InitGR.Trim());
                                        grSet.Append("|");
                                    }
                                    else
                                    {
                                        grSet.Append(" _");
                                    }
                                }
                                grSet.Append(")" + newLine);
                                
                            }

                        }
                        sw.Write(grSet.ToString()+newLine);
                        sw.Write(newLine);


                    }

                }

            }
        }

        private void btnAllModelEval_Click(object sender, EventArgs e)
        {

            string numberOfParses = "10";
            List<ParamSet1> paramSet_1 = new List<ParamSet1>();


            float init = 10f;
            float increment = 20f;
            float beta=init;

            string z2 = "(cast(SC_GR_HL_DL+1 as float)/cast(SC_HL + ## as float))";
            string z5 = "(cast(SC_GR_HP_DP as float)/cast(SC_HP + ## as float))";
            string mix_5 = "(power(cast(3 as float),Param_GRWeight) )*(" + z2 + ")*(" + z5 + ")";

            for (int i = 1; i <= 30; i++) {


                string funct = mix_5.Replace("##", ""+beta);

                paramSet_1.Add(new ParamSet1("[Rank_"+i+"]", "", "sum(" +funct + ")"));
                beta = beta + increment;
            }


                                                                                                                              
            using (StreamReader rd = new StreamReader(@"C:\Personal\Project\ParamScrips\ReRank_Parses.sql"))
            {
                string sqlCommand = rd.ReadToEnd();

                using (SSD_DepBankDataContext context = new SSD_DepBankDataContext())
                {
                    context.CommandTimeout = 600;
                    foreach (ParamSet1 p in paramSet_1)
                    {

                        string newCommand = sqlCommand.Replace("###RESULT_COLUMN", p.ResultColumn);
                        newCommand = newCommand.Replace("###CONDITION", p.Condition_Mono);
                        newCommand = newCommand.Replace(" ###SCORE_FUNCTION", p.ScoreFunction_mono);
                        newCommand = newCommand.Replace("###NUM_OF_PARSES", "10");
                        context.ExecuteQuery(typeof(int), newCommand, new object[] { });


                    }
                }
            }

            List<Param2> paramSet_2 = new List<Param2>();
            paramSet_2.Add(new Param2("[Rank_1]", "1"));
            paramSet_2.Add(new Param2("[Rank_2]", "2"));
            paramSet_2.Add(new Param2("[Rank_3]", "3"));
            paramSet_2.Add(new Param2("[Rank_4]", "4"));
            paramSet_2.Add(new Param2("[Rank_5]", "5"));
            paramSet_2.Add(new Param2("[Rank_6]", "6"));
            paramSet_2.Add(new Param2("[Rank_7]", "7"));
            paramSet_2.Add(new Param2("[Rank_8]", "8"));
            paramSet_2.Add(new Param2("[Rank_9]", "9"));
            paramSet_2.Add(new Param2("[Rank_10]", "10"));
            paramSet_2.Add(new Param2("[Rank_11]", "11"));
            paramSet_2.Add(new Param2("[Rank_12]", "12"));
            paramSet_2.Add(new Param2("[Rank_13]", "13"));
            paramSet_2.Add(new Param2("[Rank_14]", "14"));
            paramSet_2.Add(new Param2("[Rank_15]", "15"));
            paramSet_2.Add(new Param2("[Rank_16]", "16"));
            paramSet_2.Add(new Param2("[Rank_17]", "17"));
            paramSet_2.Add(new Param2("[Rank_18]", "18"));



            paramSet_2.Add(new Param2("[Rank_19]", "19"));
            paramSet_2.Add(new Param2("[Rank_20]", "20"));
            paramSet_2.Add(new Param2("[Rank_21]", "21"));
            paramSet_2.Add(new Param2("[Rank_22]", "22"));
            paramSet_2.Add(new Param2("[Rank_23]", "23"));
            paramSet_2.Add(new Param2("[Rank_24]", "24"));
            paramSet_2.Add(new Param2("[Rank_25]", "25"));
            paramSet_2.Add(new Param2("[Rank_26]", "26"));
            paramSet_2.Add(new Param2("[Rank_27]", "27"));
            paramSet_2.Add(new Param2("[Rank_28]", "28"));
            paramSet_2.Add(new Param2("[Rank_29]", "29"));
            paramSet_2.Add(new Param2("[Rank_30]", "30"));

            using (StreamReader rd = new StreamReader(@"C:\Personal\Project\ParamScrips\Score_All_Parses.sql"))
            {
                string sqlCommand = rd.ReadToEnd();

                using (SSD_DepBankDataContext context = new SSD_DepBankDataContext())
                {
                    context.CommandTimeout = 600;
                    context.ExecuteQuery(typeof(int), "use SSD_DepBank \r\n truncate table tbl_result", new object[] { });
                    foreach (Param2 p in paramSet_2)
                    {

                        string newCommand2 = sqlCommand.Replace("###RANK_COLUMN", p.RankColumn);
                        newCommand2 = newCommand2.Replace("###MODEL_ID", p.ModelID);
                        //newCommand2 = newCommand2.Replace("###SHOULD_REMOVE", " [ShouldRemove]='0' and");
                        newCommand2 = newCommand2.Replace("###SHOULD_REMOVE", "");
                        newCommand2 = newCommand2.Replace("###NUM_OF_PARSES", "10");

                        string devCommand = newCommand2.Replace("###EVAL_SET_TYPE", "'d'");
                        context.ExecuteQuery(typeof(int), devCommand, new object[] { });

                        string testCommand = newCommand2.Replace("###EVAL_SET_TYPE", "'t'");
                        context.ExecuteQuery(typeof(int), testCommand, new object[] { });


                    }
                }
            }

        }
        class ParamSet1{
            public ParamSet1(string presultColumn, string pcondition, string pscoreFunction_mono)
            {
                ResultColumn = presultColumn;
                Condition_Mono = pcondition;
                ScoreFunction_mono = pscoreFunction_mono;
            }




            public ParamSet1(string presultColumn, string pcondition_Mono, string pscoreFunction_mono, string pCondition_Bigram, string pscoreFunction_bigram)
            {
                ResultColumn = presultColumn;
                Condition_Mono = pcondition_Mono;
                ScoreFunction_mono = pscoreFunction_mono;
                
                Condition_Bigram = pCondition_Bigram;
                ScoreFunction_bigram = pscoreFunction_bigram;
                
            }
            public string ResultColumn;
            public string Condition_Mono;
            public string Condition_Bigram;
            public string ScoreFunction_mono;
            public string ScoreFunction_bigram;
        }

        class Param2 {
            public Param2(string pRankColumn, string pModelID) {
                RankColumn = pRankColumn;
                ModelID = pModelID;
            }

            public string RankColumn;
            public string ModelID;
        }

        private void btnBGramEval_Click(object sender, EventArgs e)
        {
            string numberOfParses = "10";
            List<ParamSet1> paramSet_1 = new List<ParamSet1>();

            string bi_1 = "(  (cast(BC_G1_G2_L1_L2_L3 as float)/cast(BC_L1_L2_L3+1 as float))  )";
            string bi_2 = "(  (cast(BC_G1_G2_L1_L2_L3 as float)/cast(abs(G1_SC_GR_HL_DL+G2_SC_GR_HL_DL-BC_G1_G2_L1_L2_L3+1) as float))  )";


            //string bi_3 = "(  (cast(BC_G1_G2_L1_L2_L3+BC_G1_G2_P1_P2_P3 as float)/cast(G1_SC_GR_HL_DL+G1_SC_GR_HP_DP+G2_SC_GR_HL_DL+G2_SC_GR_HP_DP-BC_G1_G2_P1_P2_P3-BC_G1_G2_L1_L2_L3+1 as float))  )";
            string bi_3 = "(cast(BC_G1_G2_L1_L2_L3 as float)*(  (1/cast(BC_G1_G2_L1_L2+1 as float))+(1/cast(BC_G1_G2_L1_L3+1 as float))+(1/cast(BC_G1_G2_L2_L3+1 as float))  ))";

            string bi_4 = "(cast(BC_G1_G2_L1_L2_L3 +BC_G1_G2_L1_P2_P3+BC_G1_G2_P1_L2_P3+BC_G1_G2_P1_P2_L3  as float)*(  (1/cast(BC_G1_G2_L1_L2+BC_G1_G2_P1_P2+1 as float))+(1/cast(BC_G1_G2_L1_L3+BC_G1_G2_P1_P3+1 as float))+(1/cast(BC_G1_G2_L2_L3+BC_G1_G2_P2_P3+1 as float))  ))";


            string bi_5 = "(  cast(BC_G1_G2_L1_L2 as float)/cast(G1_SC_GR_HL+G2_SC_GR_DL+1 as float)  )";
            string bi_6 = "(  cast(BC_G1_G2_L1_L3 as float)/cast(G1_SC_GR_HL+G2_SC_GR_DL+1 as float)  )";
            string bi_7 = "(  cast(BC_G1_G2_L2_L3 as float)/cast(G1_SC_GR_HL+G2_SC_GR_DL+1 as float)  )";
            string bi_8 = bi_5 + "+" + bi_6 + "+" + bi_7;
            string bi_9 = "( cast(BC_L1_L2_L3 as float)/cast(abs(G1_SC_HL+G1_SC_DL+G2_SC_DL-2*BC_L1_L2_L3) +1 as float) )";




            paramSet_1.Add(new ParamSet1("[Rank_1]", "", "", "", "sum(" + bi_1 + ")"));
            paramSet_1.Add(new ParamSet1("[Rank_2]", "", "", "", "avg(" + bi_1 + ")"));
            paramSet_1.Add(new ParamSet1("[Rank_3]", "", "", "", "exp(sum(log( cast(1 as float)+(" + bi_1 + "))))"));

            paramSet_1.Add(new ParamSet1("[Rank_4]", "", "", "", "sum(" + bi_2 + ")"));
            paramSet_1.Add(new ParamSet1("[Rank_5]", "", "", "", "avg(" + bi_2 + ")"));
            paramSet_1.Add(new ParamSet1("[Rank_6]", "", "", "", "exp(sum(log( cast(3 as float)+(" + bi_2 + "))))"));

            paramSet_1.Add(new ParamSet1("[Rank_7]", "", "", "", "sum(" + bi_3 + ")"));
            paramSet_1.Add(new ParamSet1("[Rank_8]", "", "", "", "avg(" + bi_3 + ")"));
            paramSet_1.Add(new ParamSet1("[Rank_9]", "", "", "", "exp(sum(log( cast(1 as float)+(" + bi_3 + "))))"));

            paramSet_1.Add(new ParamSet1("[Rank_10]", "", "", "", "sum(" + bi_4 + ")"));
            paramSet_1.Add(new ParamSet1("[Rank_11]", "", "", "", "avg(" + bi_4 + ")"));
            paramSet_1.Add(new ParamSet1("[Rank_12]", "", "", "", "exp(sum(log( cast(1 as float)+(" + bi_4 + "))))"));


            paramSet_1.Add(new ParamSet1("[Rank_13]", "", "", "", "sum(" + bi_5 + ")"));
            paramSet_1.Add(new ParamSet1("[Rank_14]", "", "", "", "avg(" + bi_5 + ")"));
            paramSet_1.Add(new ParamSet1("[Rank_15]", "", "", "", "exp(sum(log( cast(1 as float)+(" + bi_5 + "))))"));

            
            paramSet_1.Add(new ParamSet1("[Rank_16]", "", "", "", "sum(" + bi_6 + ")"));
            paramSet_1.Add(new ParamSet1("[Rank_17]", "", "", "", "avg(" + bi_6 + ")"));
            paramSet_1.Add(new ParamSet1("[Rank_18]", "", "", "", "exp(sum(log( cast(1 as float)+(" + bi_6 + "))))"));

            paramSet_1.Add(new ParamSet1("[Rank_19]", "", "", "", "sum(" + bi_7 + ")"));
            paramSet_1.Add(new ParamSet1("[Rank_20]", "", "", "", "avg(" + bi_7 + ")"));
            paramSet_1.Add(new ParamSet1("[Rank_21]", "", "", "", "exp(sum(log( cast(1 as float)+(" + bi_7 + "))))"));

            paramSet_1.Add(new ParamSet1("[Rank_22]", "", "", "", "sum(" + bi_8 + ")"));
            paramSet_1.Add(new ParamSet1("[Rank_23]", "", "", "", "avg(" + bi_8 + ")"));
            paramSet_1.Add(new ParamSet1("[Rank_24]", "", "", "", "exp(sum(log( cast(1 as float)+(" + bi_8 + "))))"));


            paramSet_1.Add(new ParamSet1("[Rank_25]", "", "", "", "sum(" + bi_9 + ")"));
            paramSet_1.Add(new ParamSet1("[Rank_26]", "", "", "", "avg(" + bi_9 + ")"));
            paramSet_1.Add(new ParamSet1("[Rank_27]", "", "", "", "exp(sum(log( cast(1 as float)+(" + bi_9 + "))))"));
          
            using (StreamReader rd = new StreamReader(@"C:\Personal\Project\ParamScrips\ReRank_Parses_bigram.sql"))
            {
                string sqlCommand = rd.ReadToEnd();

                using (SSD_DepBankDataContext context = new SSD_DepBankDataContext())
                {
                    context.CommandTimeout = 600;
                    foreach (ParamSet1 p in paramSet_1)
                    {

                        string newCommand = sqlCommand.Replace("###RESULT_COLUMN", p.ResultColumn);
                        newCommand = newCommand.Replace("###CONDITION", p.Condition_Mono);
                        newCommand = newCommand.Replace(" ###SCORE_FUNCTION", p.ScoreFunction_mono);
                        newCommand = newCommand.Replace("###NUM_OF_PARSES", "10");
                        context.ExecuteQuery(typeof(int), newCommand, new object[] { });


                    }
                }
            }

            List<Param2> paramSet_2 = new List<Param2>();
            paramSet_2.Add(new Param2("[Rank_1]", "1"));
            paramSet_2.Add(new Param2("[Rank_2]", "2"));
            paramSet_2.Add(new Param2("[Rank_3]", "3"));
            paramSet_2.Add(new Param2("[Rank_4]", "4"));
            paramSet_2.Add(new Param2("[Rank_5]", "5"));
            paramSet_2.Add(new Param2("[Rank_6]", "6"));
            paramSet_2.Add(new Param2("[Rank_7]", "7"));
            paramSet_2.Add(new Param2("[Rank_8]", "8"));
            paramSet_2.Add(new Param2("[Rank_9]", "9"));
            paramSet_2.Add(new Param2("[Rank_10]", "10"));
            paramSet_2.Add(new Param2("[Rank_11]", "11"));
            paramSet_2.Add(new Param2("[Rank_12]", "12"));
            paramSet_2.Add(new Param2("[Rank_13]", "13"));
            paramSet_2.Add(new Param2("[Rank_14]", "14"));
            paramSet_2.Add(new Param2("[Rank_15]", "15"));
            paramSet_2.Add(new Param2("[Rank_16]", "16"));
            paramSet_2.Add(new Param2("[Rank_17]", "17"));
            paramSet_2.Add(new Param2("[Rank_18]", "18"));
            paramSet_2.Add(new Param2("[Rank_19]", "19"));
            paramSet_2.Add(new Param2("[Rank_20]", "20"));
            paramSet_2.Add(new Param2("[Rank_21]", "21"));
            paramSet_2.Add(new Param2("[Rank_22]", "22"));
            paramSet_2.Add(new Param2("[Rank_23]", "23"));
            paramSet_2.Add(new Param2("[Rank_24]", "24"));
            paramSet_2.Add(new Param2("[Rank_25]", "25"));
            paramSet_2.Add(new Param2("[Rank_26]", "26"));
            paramSet_2.Add(new Param2("[Rank_27]", "27"));
            //paramSet_2.Add(new Param2("[Rank_28]", "28"));
            //paramSet_2.Add(new Param2("[Rank_29]", "29"));
            //paramSet_2.Add(new Param2("[Rank_30]", "30"));

            using (StreamReader rd = new StreamReader(@"C:\Personal\Project\ParamScrips\Score_All_Parses.sql"))
            {
                string sqlCommand = rd.ReadToEnd();

                using (SSD_DepBankDataContext context = new SSD_DepBankDataContext())
                {
                    context.CommandTimeout = 600;
                    context.ExecuteQuery(typeof(int), "use SSD_DepBank \r\n truncate table tbl_result", new object[] { });
                    foreach (Param2 p in paramSet_2)
                    {

                        string newCommand2 = sqlCommand.Replace("###RANK_COLUMN", p.RankColumn);
                        newCommand2 = newCommand2.Replace("###MODEL_ID", p.ModelID);
                        //newCommand2 = newCommand2.Replace("###SHOULD_REMOVE", " [ShouldRemove]='0' and");
                        newCommand2 = newCommand2.Replace("###SHOULD_REMOVE", "");
                        newCommand2 = newCommand2.Replace("###NUM_OF_PARSES", "10");

                        string devCommand = newCommand2.Replace("###EVAL_SET_TYPE", "'d'");
                        context.ExecuteQuery(typeof(int), devCommand, new object[] { });

                        string testCommand = newCommand2.Replace("###EVAL_SET_TYPE", "'t'");
                        context.ExecuteQuery(typeof(int), testCommand, new object[] { });


                    }
                }
            }
        }

        private void btnScoreAllParses_Click(object sender, EventArgs e)
        {


            List<Param2> paramSet_2 = new List<Param2>();
            List<ParamSet1> paramSet_1 = new List<ParamSet1>();
            

             string z1 = "power(cast(4 as float),[Param_GRWeight])*(cast(SC_GR_HL_DL+1 as float)/cast(SC_GR_HL+ 1 as float))";
            string z2 = "power(cast(4 as float),[Param_GRWeight])*(cast(SC_GR_HL_DL+1 as float)/cast(SC_HL+1 as float))";
            string z3 = "power(cast(4 as float),[Param_GRWeight])*((cast(SC_GR_HL_DL+1 as float)/cast(SC_GR_HL+1 as float)) + (cast(SC_GR_HL_DL as float)/cast( SC_HL+1 as float)))";

            string z4 = "(cast(SC_GR_HP_DP as float)/cast(SC_GR_HP+1 as float))";
            string z5 = "(cast(SC_GR_HP_DP as float)/cast(SC_HP +1 as float))";

            string mix_4 = "(" + z1 + ")*(" + z4 + ")";
            string mix_5 = "(" + z2 + ")*(" + z5 + ")";
            string mix_6 = mix_4 + "+" + mix_5;

            paramSet_1.Add(new ParamSet1("[Rank_1]", "", "sum(" + z1 + ")"));
            paramSet_1.Add(new ParamSet1("[Rank_2]", "", "avg(" + z1 + " )"));
            paramSet_1.Add(new ParamSet1("[Rank_3]", "", "exp(sum(log(1+( " + z1 + "))))"));

            paramSet_1.Add(new ParamSet1("[Rank_4]", "", "sum(" + z2 + ")"));
            paramSet_1.Add(new ParamSet1("[Rank_5]", "", "avg(" + z2 + ")"));
            paramSet_1.Add(new ParamSet1("[Rank_6]", "", "exp(sum(log(1+(" + z2 + "))))"));

            paramSet_1.Add(new ParamSet1("[Rank_7]", "", "sum(" + z3 + " )"));
            paramSet_1.Add(new ParamSet1("[Rank_8]", "", "avg(" + z3 + " )"));
            paramSet_1.Add(new ParamSet1("[Rank_9]", "", "exp(sum(log(1+(" + z3 + " ))))"));

            paramSet_1.Add(new ParamSet1("[Rank_10]", "", "sum(" + mix_4 + " )"));
            paramSet_1.Add(new ParamSet1("[Rank_11]", "", "avg(" + mix_4 + " )"));
            paramSet_1.Add(new ParamSet1("[Rank_12]", "", "exp(sum(log(1+(" + mix_4 + " ))))"));

            paramSet_1.Add(new ParamSet1("[Rank_13]", "", "sum(" + mix_5 + " )"));
            paramSet_1.Add(new ParamSet1("[Rank_14]", "", "avg(" + mix_5 + " )"));
            paramSet_1.Add(new ParamSet1("[Rank_15]", "", "exp(sum(log(1+(" + mix_5 + " ))))"));

            paramSet_1.Add(new ParamSet1("[Rank_16]", "", "sum(" + mix_6 + " )"));
            paramSet_1.Add(new ParamSet1("[Rank_17]", "", "avg(" + mix_6 + " )"));
            paramSet_1.Add(new ParamSet1("[Rank_18]", "", "exp(sum(log(1+(" + mix_6 + " ))))"));


            using (StreamReader rd = new StreamReader(@"C:\Personal\Project\ParamScrips\Score_All_Parses.sql"))
            {
                string sqlCommand = rd.ReadToEnd();

                using (SSD_DepBankDataContext context = new SSD_DepBankDataContext())
                {
                    context.CommandTimeout = 600;
                    context.ExecuteQuery(typeof(int), "use SSD_DepBank \r\n truncate table tbl_result", new object[] { });
                    foreach (Param2 p in paramSet_2)
                    {

                        string newCommand2 = sqlCommand.Replace("###RANK_COLUMN", p.RankColumn);
                        newCommand2 = newCommand2.Replace("###MODEL_ID", p.ModelID);
                        newCommand2 = newCommand2.Replace("###SHOULD_REMOVE", " [ShouldRemove]='0' and");
                        //newCommand2 = newCommand2.Replace("###SHOULD_REMOVE", "");
                        newCommand2 = newCommand2.Replace("###NUM_OF_PARSES", "10");

                        string devCommand = newCommand2.Replace("###EVAL_SET_TYPE", "'d'");
                        context.ExecuteQuery(typeof(int), devCommand, new object[] { });

                        string testCommand = newCommand2.Replace("###EVAL_SET_TYPE", "'t'");
                        context.ExecuteQuery(typeof(int), testCommand, new object[] { });


                    }
                }
            }
        }

        private void btnHybrid_Click(object sender, EventArgs e)
        {
            List<ParamSet1> paramSet_1 = new List<ParamSet1>();





            string p1 = "(cast(1 as float) + (cast(BC_G1_L1_L3 as float)/cast(G1_SC_GR_HL+1 as float)))";
            string p2 = "(cast(1 as float) + (cast(BC_G2_L1_L3 as float)/cast(G2_SC_HL+1 as float)))";
            string p3 = "(cast(1 as float) + (cast(G1_SC_GR_HL_DL as float)/cast(G1_SC_GR_HL+1 as float)))";
            string p4 = "(cast(1 as float) + (cast(G1_SC_GR_HL as float)/cast(G1_SC_HL+1 as float)))";

            string func = "*";
            string score = p1 + func + p2 + func + p3 + func + p4;



            string mp_1 = "avg((cast(SC_GR_HL_DL as float)/cast(SC_HL+1 as float))+(cast(SC_GR_HL_DL as float)/cast(SC_GR_HL+1 as float))+(cast(SC_GR_HL_DL as float)/cast(SC_DL+1 as float))+(cast(SC_GR_HL_DL as float)/cast(SC_GR_DL+1 as float))+(cast(SC_GR_HL_DL as float)/cast(SC_HL+SC_DL-SC_GR_HL_DL+1 as float))+(cast(SC_GR_HL_DL as float)/cast(SC_HL_DL+1 as float)))";
            string mp_2 = "sum((cast(SC_GR_HL_DL as float)/cast(SC_HL+1 as float))+(cast(SC_GR_HL_DL as float)/cast(SC_GR_HL+1 as float))+(cast(SC_GR_HL_DL as float)/cast(SC_DL+1 as float))+(cast(SC_GR_HL_DL as float)/cast(SC_GR_DL+1 as float))+(cast(SC_GR_HL_DL as float)/cast(SC_HL+SC_DL-SC_GR_HL_DL+1 as float))+(cast(SC_GR_HL_DL as float)/cast(SC_HL_DL+1 as float)))";
            string mp_3 = "exp(sum(log( 1+(cast(SC_GR_HL_DL as float)/cast(SC_HL+1 as float))+(cast(SC_GR_HL_DL as float)/cast(SC_GR_HL+1 as float))+(cast(SC_GR_HL_DL as float)/cast(SC_DL+1 as float))+(cast(SC_GR_HL_DL as float)/cast(SC_GR_DL+1 as float))+(cast(SC_GR_HL_DL as float)/cast(SC_HL+SC_DL-SC_GR_HL_DL+1 as float))+(cast(SC_GR_HL_DL as float)/cast(SC_HL_DL+1 as float)))))";

            string mp_4 = "avg( (cast(SC_GR_HL_DL + SC_GR_HP_DP as float)/cast(SC_HL+SC_HP+1 as float))+(cast(SC_GR_HL_DL + SC_GR_HP_DP as float)/cast(SC_GR_HL+SC_GR_HP+1 as float))+(cast(SC_GR_HL_DL+SC_GR_HP_DP as float)/cast(SC_DL+ SC_DP+1 as float))+(cast(SC_GR_HL_DL+SC_GR_HP_DP as float)/cast(SC_GR_DL+ SC_GR_DP+1 as float))+(cast(SC_GR_HL_DL+SC_GR_HP_DP as float)/cast(SC_HL+SC_DL+SC_HP+SC_DP-SC_GR_HL_DL-SC_GR_HP_DP+1 as float))+(cast(SC_GR_HL_DL+SC_GR_HP_DP as float)/cast(SC_GR_HL+SC_GR_DL+SC_GR_HP+SC_GR_DP-SC_GR_HL_DL-SC_GR_HP_DP+1 as float)))";
            string mp_5 = "sum( (cast(SC_GR_HL_DL + SC_GR_HP_DP as float)/cast(SC_HL+SC_HP+1 as float))+(cast(SC_GR_HL_DL + SC_GR_HP_DP as float)/cast(SC_GR_HL+SC_GR_HP+1 as float))+(cast(SC_GR_HL_DL+SC_GR_HP_DP as float)/cast(SC_DL+ SC_DP+1 as float))+(cast(SC_GR_HL_DL+SC_GR_HP_DP as float)/cast(SC_GR_DL+ SC_GR_DP+1 as float))+(cast(SC_GR_HL_DL+SC_GR_HP_DP as float)/cast(SC_HL+SC_DL+SC_HP+SC_DP-SC_GR_HL_DL-SC_GR_HP_DP+1 as float))+(cast(SC_GR_HL_DL+SC_GR_HP_DP as float)/cast(SC_GR_HL+SC_GR_DL+SC_GR_HP+SC_GR_DP-SC_GR_HL_DL-SC_GR_HP_DP+1 as float)))";
            string mp_6 = "exp(sum(log( 1+(cast(SC_GR_HL_DL + SC_GR_HP_DP as float)/cast(SC_HL+SC_HP+1 as float))+(cast(SC_GR_HL_DL + SC_GR_HP_DP as float)/cast(SC_GR_HL+SC_GR_HP+1 as float))+(cast(SC_GR_HL_DL+SC_GR_HP_DP as float)/cast(SC_DL+ SC_DP+1 as float))+(cast(SC_GR_HL_DL+SC_GR_HP_DP as float)/cast(SC_GR_DL+ SC_GR_DP+1 as float))+(cast(SC_GR_HL_DL+SC_GR_HP_DP as float)/cast(SC_HL+SC_DL+SC_HP+SC_DP-SC_GR_HL_DL-SC_GR_HP_DP+1 as float))+(cast(SC_GR_HL_DL+SC_GR_HP_DP as float)/cast(SC_GR_HL+SC_GR_DL+SC_GR_HP+SC_GR_DP-SC_GR_HL_DL-SC_GR_HP_DP+1 as float)))))";

            string model_m_1 = mp_1 + "+" + mp_2 + "+" + mp_3;
            string model_m_2 = mp_4 + "+" + mp_5 + "+" + mp_6;




            paramSet_1.Add(new ParamSet1("[Rank_1]", "", model_m_1, "", "avg(" + score + ")"));
            paramSet_1.Add(new ParamSet1("[Rank_2]", "", model_m_1, "", "sum(" + score + ")"));
            paramSet_1.Add(new ParamSet1("[Rank_3]", "", model_m_1, "", "exp(sum(log((" + score + "))))"));



            paramSet_1.Add(new ParamSet1("[Rank_4]", "", model_m_2, "", "avg(" + score + ")"));
            paramSet_1.Add(new ParamSet1("[Rank_5]", "", model_m_2, "", "sum(" + score + ")"));
            paramSet_1.Add(new ParamSet1("[Rank_6]", "", model_m_2, "", "exp(sum(log((" + score + "))))"));




            using (StreamReader rd = new StreamReader(@"C:\Personal\Project\ParamScrips\ReRank_Parses_conj.sql"))
            {
                string sqlCommand = rd.ReadToEnd();

                using (SSD_DepBankDataContext context = new SSD_DepBankDataContext())
                {
                    context.CommandTimeout = 600;
                    foreach (ParamSet1 p in paramSet_1)
                    {

                        string newCommand = sqlCommand.Replace("###RESULT_COLUMN", p.ResultColumn);
                        newCommand = newCommand.Replace("###CONDITION_MONO", p.Condition_Mono);
                        newCommand = newCommand.Replace(" ###SCORE_FUNCTION_MONO", p.ScoreFunction_mono);
                        newCommand = newCommand.Replace(" ###SCORE_FUNCTION_BI", p.ScoreFunction_bigram);
                        newCommand = newCommand.Replace(" ###CONDITION_BI", p.Condition_Bigram);
                        newCommand = newCommand.Replace("###NUM_OF_PARSES", "10");
                        context.ExecuteQuery(typeof(int), newCommand, new object[] { });


                    }
                }
            }

            List<Param2> paramSet_2 = new List<Param2>();
            paramSet_2.Add(new Param2("[Rank_1]", "1"));
            paramSet_2.Add(new Param2("[Rank_2]", "2"));
            paramSet_2.Add(new Param2("[Rank_3]", "3"));
            paramSet_2.Add(new Param2("[Rank_4]", "4"));
            paramSet_2.Add(new Param2("[Rank_5]", "5"));
            paramSet_2.Add(new Param2("[Rank_6]", "6"));
            paramSet_2.Add(new Param2("[Rank_7]", "7"));
            paramSet_2.Add(new Param2("[Rank_8]", "8"));
            paramSet_2.Add(new Param2("[Rank_9]", "9"));
            paramSet_2.Add(new Param2("[Rank_10]", "10"));
            paramSet_2.Add(new Param2("[Rank_11]", "11"));
            paramSet_2.Add(new Param2("[Rank_12]", "12"));
            paramSet_2.Add(new Param2("[Rank_13]", "13"));
            paramSet_2.Add(new Param2("[Rank_14]", "14"));
            paramSet_2.Add(new Param2("[Rank_15]", "15"));
            paramSet_2.Add(new Param2("[Rank_16]", "16"));
            paramSet_2.Add(new Param2("[Rank_17]", "17"));
            paramSet_2.Add(new Param2("[Rank_18]", "18"));
            //paramSet_2.Add(new Param2("[Rank_19]", "19"));
            //paramSet_2.Add(new Param2("[Rank_20]", "20"));
            //paramSet_2.Add(new Param2("[Rank_21]", "21"));
            //paramSet_2.Add(new Param2("[Rank_22]", "22"));
            //paramSet_2.Add(new Param2("[Rank_23]", "23"));
            //paramSet_2.Add(new Param2("[Rank_24]", "24"));
            //paramSet_2.Add(new Param2("[Rank_25]", "25"));
            //paramSet_2.Add(new Param2("[Rank_26]", "26"));
            //paramSet_2.Add(new Param2("[Rank_27]", "27"));
            //paramSet_2.Add(new Param2("[Rank_28]", "28"));
            //paramSet_2.Add(new Param2("[Rank_29]", "29"));
            //paramSet_2.Add(new Param2("[Rank_30]", "30"));


            using (StreamReader rd = new StreamReader(@"C:\Personal\Project\ParamScrips\Score_All_Parses.sql"))
            {
                string sqlCommand = rd.ReadToEnd();

                using (SSD_DepBankDataContext context = new SSD_DepBankDataContext())
                {
                    context.CommandTimeout = 600;
                    context.ExecuteQuery(typeof(int), "use SSD_DepBank \r\n truncate table tbl_result", new object[] { });
                    foreach (Param2 p in paramSet_2)
                    {

                        string newCommand2 = sqlCommand.Replace("###RANK_COLUMN", p.RankColumn);
                        newCommand2 = newCommand2.Replace("###MODEL_ID", p.ModelID);
                        //newCommand2 = newCommand2.Replace("###SHOULD_REMOVE", " [ShouldRemove]='0' and");
                        newCommand2 = newCommand2.Replace("###SHOULD_REMOVE", "");
                        newCommand2 = newCommand2.Replace("###NUM_OF_PARSES", "10");

                        string devCommand = newCommand2.Replace("###EVAL_SET_TYPE", "'d'");
                        context.ExecuteQuery(typeof(int), devCommand, new object[] { });

                        string testCommand = newCommand2.Replace("###EVAL_SET_TYPE", "'t'");
                        context.ExecuteQuery(typeof(int), testCommand, new object[] { });


                    }
                }
            }
        }



        private void Sri() {

            List<ParamSet1> paramSet_1 = new List<ParamSet1>();
            string B_Score_1 = "(  (cast(BC_G1_G2_L1_L2_L3 as float)/cast(BC_L1_L2_L3+1 as float))  )";
            string B_Score_2 = "(  (cast(BC_G1_G2_L1_L2_L3 as float)/cast(G1_SC_GR_HL_DL+G2_SC_GR_HL_DL-BC_G1_G2_L1_L2_L3+1 as float))  )";


            //string bi_3 = "(  (cast(BC_G1_G2_L1_L2_L3+BC_G1_G2_P1_P2_P3 as float)/cast(G1_SC_GR_HL_DL+G1_SC_GR_HP_DP+G2_SC_GR_HL_DL+G2_SC_GR_HP_DP-BC_G1_G2_P1_P2_P3-BC_G1_G2_L1_L2_L3+1 as float))  )";
            string B_Score_3 = "(cast(BC_G1_G2_L1_L2_L3 as float)*(  (1/cast(BC_G1_G2_L1_L2+1 as float))+(1/cast(BC_G1_G2_L1_L3+1 as float))+(1/cast(BC_G1_G2_L2_L3+1 as float))  ))";

            string B_Score_4 = "(cast(BC_G1_G2_L1_L2_L3 +BC_G1_G2_L1_P2_P3+BC_G1_G2_P1_L2_P3+BC_G1_G2_P1_P2_L3  as float)*(  (1/cast(BC_G1_G2_L1_L2+BC_G1_G2_P1_P2+1 as float))+(1/cast(BC_G1_G2_L1_L3+BC_G1_G2_P1_P3+1 as float))+(1/cast(BC_G1_G2_L2_L3+BC_G1_G2_P2_P3+1 as float))  ))";


            string B_Score_5 = "(  cast(BC_G1_G2_L1_L2 as float)/cast(G1_SC_GR_HL+G2_SC_GR_DL+1 as float)  )";
            string B_Score_6 = "(  cast(BC_G1_G2_L1_L3 as float)/cast(G1_SC_GR_HL+G2_SC_GR_DL+1 as float)  )";
            string B_Score_7 = "(  cast(BC_G1_G2_L2_L3 as float)/cast(G1_SC_GR_HL+G2_SC_GR_DL+1 as float)  )";
            string B_Score_8 = B_Score_5 + "+" + B_Score_6 + "+" + B_Score_7;
            string B_Score_9 = "( cast(BC_L1_L2_L3 as float)/cast(G1_SC_HL+G1_SC_DL+G2_SC_DL-2*BC_L1_L2_L3 +1 as float) )";





            paramSet_1.Add(new ParamSet1("[Rank_1]", "", "", "", "avg(" + B_Score_1 + ")"));
            paramSet_1.Add(new ParamSet1("[Rank_2]", "", "", "", "sum(" + B_Score_1 + ")"));
            paramSet_1.Add(new ParamSet1("[Rank_3]", "", "", "", "exp(sum(log( cast(1 as float)+(" + B_Score_1 + "))))"));

            paramSet_1.Add(new ParamSet1("[Rank_4]", "", "", "", "avg(" + B_Score_2 + ")"));
            paramSet_1.Add(new ParamSet1("[Rank_5]", "", "", "", "sum(" + B_Score_2 + ")"));
            paramSet_1.Add(new ParamSet1("[Rank_6]", "", "", "", "exp(sum(log( cast(3 as float)+(" + B_Score_2 + "))))"));

            paramSet_1.Add(new ParamSet1("[Rank_7]", "", "", "", "avg(" + B_Score_3 + ")"));
            paramSet_1.Add(new ParamSet1("[Rank_8]", "", "", "", "sum(" + B_Score_3 + ")"));
            paramSet_1.Add(new ParamSet1("[Rank_9]", "", "", "", "exp(sum(log( cast(1 as float)+(" + B_Score_3 + "))))"));

            paramSet_1.Add(new ParamSet1("[Rank_10]", "", "", "", "avg(" + B_Score_4 + ")"));
            paramSet_1.Add(new ParamSet1("[Rank_11]", "", "", "", "sum(" + B_Score_4 + ")"));
            paramSet_1.Add(new ParamSet1("[Rank_12]", "", "", "", "exp(sum(log( cast(1 as float)+(" + B_Score_4 + "))))"));



            paramSet_1.Add(new ParamSet1("[Rank_13]", "", "", "", "avg(" + B_Score_5 + ")"));
            paramSet_1.Add(new ParamSet1("[Rank_14]", "", "", "", "sum(" + B_Score_5 + ")"));
            paramSet_1.Add(new ParamSet1("[Rank_15]", "", "", "", "exp(sum(log( cast(1 as float)+(" + B_Score_5 + "))))"));


            paramSet_1.Add(new ParamSet1("[Rank_16]", "", "", "", "avg(" + B_Score_6 + ")"));
            paramSet_1.Add(new ParamSet1("[Rank_17]", "", "", "", "sum(" + B_Score_6 + ")"));
            paramSet_1.Add(new ParamSet1("[Rank_18]", "", "", "", "exp(sum(log( cast(1 as float)+(" + B_Score_6 + "))))"));


            paramSet_1.Add(new ParamSet1("[Rank_19]", "", "", "", "avg(" + B_Score_7 + ")"));
            paramSet_1.Add(new ParamSet1("[Rank_20]", "", "", "", "sum(" + B_Score_7 + ")"));
            paramSet_1.Add(new ParamSet1("[Rank_21]", "", "", "", "exp(sum(log( cast(1 as float)+(" + B_Score_7 + "))))"));


            paramSet_1.Add(new ParamSet1("[Rank_22]", "", "", "", "avg(" + B_Score_8 + ")"));
            paramSet_1.Add(new ParamSet1("[Rank_23]", "", "", "", "sum(" + B_Score_8 + ")"));
            paramSet_1.Add(new ParamSet1("[Rank_24]", "", "", "", "exp(sum(log( cast(1 as float)+(" + B_Score_8 + "))))"));



            paramSet_1.Add(new ParamSet1("[Rank_25]", "", "", "", "avg(" + B_Score_9 + ")"));
            paramSet_1.Add(new ParamSet1("[Rank_26]", "", "", "", "sum(" + B_Score_9 + ")"));
            paramSet_1.Add(new ParamSet1("[Rank_27]", "", "", "", "exp(sum(log( cast(1 as float)+(" + B_Score_9 + "))))"));
        }
    }

    public class CustomEval
    {
        IRASPEval _evaluationInterface;
        TBL_Eval _evalItem;
        public TBL_Eval Item
        {
            get
            {
                return _evalItem;
            }
        }
        public CustomEval(IRASPEval pEvalInterface, TBL_Eval pEvalItem)
        {
            _evaluationInterface = pEvalInterface;
            _evalItem = pEvalItem;
        }

        public bool Equals(TBL_GoldStandard_GR obj)
        {
            if (obj.GetType() == typeof(TBL_GoldStandard_GR))
            {
                TBL_GoldStandard_GR goldStd = (TBL_GoldStandard_GR)obj;
                return _evaluationInterface.IsEqual(_evalItem, goldStd);
            }
            else
            {
                return false;
            }


        }

    }

    public class FullEvalAlgo : IRASPEval
    {


        public bool IsEqual(TBL_Eval pEval, TBL_GoldStandard_GR pGoldStd)
        {
            if (pEval.GRType.Trim() == pGoldStd.GRType.Trim() && pEval.H_Word.Trim() == pGoldStd.H_Word.Trim() && pEval.D_Word.Trim() == pGoldStd.D_Word.Trim() &&
                pEval.SubType.Trim() == pGoldStd.SubType.Trim() && pEval.InitGR.Trim() == pGoldStd.InitGR.Trim())
            {

                return true;
            }
            else
            {
                return false;
            }
        }
    }

    public interface IRASPEval
    {
        bool IsEqual(TBL_Eval pEval, TBL_GoldStandard_GR pGoldStd);
    }
}


